package com.qianfeng.exam.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.qianfeng.exam.constants.ResultCode;

@JsonInclude(JsonInclude.Include.NON_EMPTY)//null值 属性不输出
public class R {

    private int code;//状态码,通过状态可以快速的识别出是什么结果,相同状态不管在什么接口中应该使用同一个状态码

    private String msg;//针对状态码的提示

    private Object data; //给前端传递的值



    public static R setOk(Object data, String s){
        return setError(ResultCode.SUCCESS,s,data);
    }

    public static R setError(Object data){
        return setError(ResultCode.FAIL,"网络异常,请检查您的网络",data);
    }

    public static R setError(int code, String msg, Object data){
       R r = new R();
       r.setCode(code);
       r.setMsg(msg);
       r.setData(data);
       return r;

    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

}
